package com.boc.news.beans;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class EncryptMD5 {
	public EncryptMD5(){
		
	}
	/**
	 * MD5�����㷨
	 * @param str
	 * @return String
	 */
	public static String MD5(String str){
		char hexDigits[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
				'a', 'b', 'c', 'd','e', 'f'}; 
		try { 
			byte[] strTemp = str.getBytes(); 
			MessageDigest mdTemp = MessageDigest.getInstance("MD5"); 
			mdTemp.update(strTemp); 
			byte[] md = mdTemp.digest(); 
			int j = md.length; 
			char ch[] = new char[j * 2]; 
			int k = 0; 
			for (int i = 0; i < j; i++) { 
				byte byte0 = md[i]; 
				ch[k++] = hexDigits[byte0 >>> 4 & 0xf]; 
				ch[k++] = hexDigits[byte0 & 0xf]; 
			} 
			return new String(ch); 
		} 
		catch (NoSuchAlgorithmException e){ 
			e.printStackTrace();
			return null;
		}
	}
	public static void main(String[] args) {
		//String random = "602003140966003733";
		//String pwd = "8ad618d6ff742e7860ee500601284311";
		String s = new EncryptMD5().MD5("adminqazwsxedc");
		System.out.println(s);
	}
}
